<?php

/**
 * This is the model class for table "xman_event".
 *
 * The followings are the available columns in table 'xman_event':
 * @property integer $event_id
 * @property string $event_start_date
 * @property string $event_end_date
 * @property string $event_location
 * @property integer $event_schedule_id
 *
 * The followings are the available model relations:
 * @property Schedule $eventSchedule
 * @property EventUser[] $eventUsers
 */
class Event extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Event the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_event';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('event_schedule_id', 'required'),
			array('event_schedule_id', 'numerical', 'integerOnly'=>true),
			array('event_location', 'length', 'max'=>50),
			array('event_start_date, event_end_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('event_id, event_start_date, event_end_date, event_location, event_schedule_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'eventSchedule' => array(self::BELONGS_TO, 'Schedule', 'event_schedule_id'),
			'eventUsers' => array(self::HAS_MANY, 'EventUser', 'event_user_event_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'event_id' => 'Event',
			'event_start_date' => 'Event Start Date',
			'event_end_date' => 'Event End Date',
			'event_location' => 'Event Location',
			'event_schedule_id' => 'Event Schedule',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('event_id',$this->event_id);
		$criteria->compare('event_start_date',$this->event_start_date,true);
		$criteria->compare('event_end_date',$this->event_end_date,true);
		$criteria->compare('event_location',$this->event_location,true);
		$criteria->compare('event_schedule_id',$this->event_schedule_id);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}